<template>
    <div>
        <van-divider>在线投诉</van-divider>
        <van-form >
            <van-field
                v-model="complaints.username"
                username="姓名"
                label="姓名"
                placeholder="姓名"
                :rules="[{ required: true, message: '请填写姓名' }]"
            />
            <van-field
                v-model="complaints.phone"
                type="phone"
                name="联系方式"
                label="联系方式"
                placeholder="联系方式"
                :rules="[{ required: true, message: '请填写联系方式' }]"
            />
            <van-field
                v-model="complaints.address"
                type="address"
                name="住址"
                label="住址"
                placeholder="住址"
                :rules="[{ required: true, message: '请填写住址' }]"
            />
            <van-field
                v-model="complaints.Calendar"
                type="Calendar"
                name="投诉日期"
                label="投诉日期"
                placeholder="日期"
                :rules="[{ required: true, message: '请填写日期' }]"
            />
            <van-field
                v-model="complaints.message"
                rows="4"
                autosize
                label="投诉内容"
                type="textarea"
                maxlength="100"
                placeholder="请输入"
                show-word-limit
            />
            <!-- <van-field name="uploader" label="上传照片">
                <template #input>
                    <van-uploader v-model="complaints.uploader" />
                </template>
            </van-field> -->
            <van-field name="radio" label="紧急度">
                <template #input>
                    <van-radio-group v-model="complaints.radio" direction="horizontal">
                    <van-radio name="一般">一般</van-radio>
                    <van-radio name="紧急">紧急</van-radio>
                    <van-radio name="特急">特急</van-radio>
                    </van-radio-group>
                </template>
            </van-field>

            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit" @click="aa">提交</van-button>
            </div>
        </van-form>
    </div>
</template>
<script>
export default {
  data() {
    return {
        complaints:{
            username: '',
            phone: '',
            address: '',
            message: '',
            radio: '1',
            // uploader: [],
            Calendar: '',
        }
    };
  },
  methods: {
    onSubmit(values) {
      console.log('submit', values);
    },
    comform(){
      this.$router.push("/complaints")
    },
    aa(){
      this.$axios
        .post('/ComplaintsForm/addOne',this.complaints)
        .then(res=>{ //提交成功
            if(res.data.code == 1){
                alert("提交成功")
                this.$router.push("/complaints");
            }else if(res.data.code == 0){
                alert("提交失败")
                this.$router.push("/comform");
            }
        })
        .catch(error=>{
            console.log(error);
        });
    },
        // to(){
        //     this.$router.push('/complaints')
        // }
  },
};
</script>